import 'package:flutter/material.dart';
import 'package:flutter_base/getx_demo/models/counter_controller.dart';
import 'package:get/get.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  /*
  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      init: CounterController(),
      builder: (controller) => Scaffold(
        appBar: AppBar(
          title: const Text('GetX首页'),
        ),
        body: Center(
          child: Text(
            '${controller.counter}',
            style: const TextStyle(fontSize: 18.0),
          ),
        ),
        floatingActionButton: ElevatedButton(
          onPressed: () {
            controller.increment();
          },
          child: const Icon(Icons.add),
        ),
      ),
    );
  }
  */
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('GetX首页'),
      ),
      body: Center(
        child: GetBuilder<CounterController>(
          init: CounterController(),
          builder: (controller) => Text(
            '${controller.counter}',
            style: const TextStyle(fontSize: 18.0),
          ),
        ),
      ),
      floatingActionButton: ElevatedButton(
        onPressed: () {
          CounterController.to.increment();
        },
        child: const Icon(Icons.add),
      ),
    );
  }
}
